package com.jackmo.controller;

import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class TestController {

    @GetMapping("/hello")
    public String hello(@RequestParam String name) {
        return "Hello, " + name + "!";
    }

    @PostMapping("/user")
    public User createUser(@RequestBody User user) {
        return user; // 模拟返回创建的用户
    }

    @GetMapping("/error")
    public String triggerError() {
        throw new RuntimeException("Test Exception!");
    }

    // 内部类
    static class User {
        private String name;
        private int age;
        
        // Getters and Setters
        public String getName() { return name; }
        public void setName(String name) { this.name = name; }
        public int getAge() { return age; }
        public void setAge(int age) { this.age = age; }
        
        @Override
        public String toString() {
            return "User{name='" + name + "', age=" + age + "}";
        }
    }
}